package com.wr.modules.system.service.impl;

import com.wr.api.system.domain.SysRoleBo;
import com.wr.api.system.domain.SysUserBo;
import com.wr.modules.system.service.ISysMenuService;
import com.wr.modules.system.service.ISysPermissionService;
import com.wr.modules.system.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author MyPC
 */
@Service
public class SysPermissionServiceImpl implements ISysPermissionService {

    @Autowired
    private ISysRoleService iSysRoleService;

    @Autowired
    private ISysMenuService iSysMenuService;

    @Override
    public Set<String> getRolePermission(SysUserBo sysUserBo) {
        Set<String> roles = new HashSet<String>();
        // 管理员拥有所有权限
        if (sysUserBo.isAdmin()) {
            roles.add("admin");
//        } else {
//            roles.addAll(iSysRoleService.selectRolePermissionByUserId(sysUserBo.getUserId()));
        }
        return roles;
    }

    @Override
    public Set<String> getMenuPermission(SysUserBo sysUserBo) {
        Set<String> perms = new HashSet<String>();
        // 管理员拥有所有权限
        if (sysUserBo.isAdmin()) {
            perms.add("*:*:*");
        } else {
            List<SysRoleBo> sysRoleBos = sysUserBo.getSysRoleBos();
//            if (!StringUtils.isEmpty(sysRoleBos)) {
//                // 多角色设置permissions属性，以便数据权限匹配权限
//                for (SysRoleBo sysRoleBo : sysRoleBos) {
//                    Set<String> rolePerms = iSysMenuService.selectMenuPermsByRoleId(sysRoleBo.getRoleId());
//                    sysRoleBo.setPermissions(rolePerms);
//                    perms.addAll(rolePerms);
//                }
//            } else {
//                perms.addAll(iSysMenuService.selectMenuPermsByUserId(sysUserBo.getUserId()));
//            }
        }
        return perms;
    }
}
